package com.tsj.spzx.config;

import com.tsj.spzx.Interceptor.LoginInterceptor;
import com.tsj.spzx.properties.UserLoginInterceptorUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration    // 通过此注解springboot就会将其注册为bean
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private UserLoginInterceptorUrl loginInterceptorUrl;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")    // 对所有请求都拦截
                .excludePathPatterns(loginInterceptorUrl.getExcludeUrls());   // 除了以下请求不拦截
    }
}
